package com.example.smarqueeview

import android.app.Application
import androidx.multidex.MultiDex
import androidx.multidex.MultiDex.install
import com.elvishew.xlog.LogConfiguration
import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.XLog
import com.elvishew.xlog.printer.AndroidPrinter
import com.elvishew.xlog.printer.ConsolePrinter
import com.elvishew.xlog.printer.Printer
import com.example.smarqueeview.log.MyJsonFormatter
import com.ooftf.director.app.Director.init

/**
 * @author
 * @date 2021/6/29.
 * description：
 */
class App : Application() {
    override fun onCreate() {
        super.onCreate()
        install(this)
        init("06a708c091e3d5543e5bcfcf1831e514", BuildConfig.DEBUG) //第一个参数id需要在官网控制台查看自己的
        //        DoKit.Builder(this)
//                .productId("06a708c091e3d5543e5bcfcf1831e514")
//                .build();
//        instance = this;
        initXLog()

    }

    private fun initXLog() {
        val config = LogConfiguration.Builder()
            .logLevel(
                if (BuildConfig.DEBUG) LogLevel.ALL // Specify log level, logs below this level won't be printed, default: LogLevel.ALL
                else LogLevel.NONE
            )
            .tag(getString(R.string.global_tag)) // Specify TAG, default: "X-LOG"
            // .enableThreadInfo()                                 // Enable thread info, disabled by default
            // .enableStackTrace(2)                                // Enable stack trace info with depth 2, disabled by default
            // .enableBorder()                                     // Enable border, disabled by default
            .jsonFormatter(MyJsonFormatter()) // Default: DefaultJsonFormatter
            // .xmlFormatter(new MyXmlFormatter())                 // Default: DefaultXmlFormatter
            // .throwableFormatter(new MyThrowableFormatter())     // Default: DefaultThrowableFormatter
            // .threadFormatter(new MyThreadFormatter())           // Default: DefaultThreadFormatter
            // .stackTraceFormatter(new MyStackTraceFormatter())   // Default: DefaultStackTraceFormatter
            // .borderFormatter(new MyBoardFormatter())            // Default: DefaultBorderFormatter
            // .addObjectFormatter(AnyClass.class,                 // Add formatter for specific class of object
            //     new AnyClassObjectFormatter())                  // Use Object.toString() by default
            //                .addInterceptor(new BlacklistTagsFilterInterceptor(    // Add blacklist tags filter
            //                        "blacklist1", "blacklist2", "blacklist3"))
            // .addInterceptor(new WhitelistTagsFilterInterceptor( // Add whitelist tags filter
            //     "whitelist1", "whitelist2", "whitelist3"))
            // .addInterceptor(new MyInterceptor())                // Add a log interceptor
            .build()
        val androidPrinter: Printer =
            AndroidPrinter() // Printer that print the log using android.util.Log
        val conslePrinter: Printer =
            ConsolePrinter() // Printer that print the log using android.util.Log
        //        Printer filePrinter = new FilePrinter                      // Printer that print the log to the file system
//                .Builder(new File(getExternalCacheDir().getAbsolutePath(), "log").getPath())       // Specify the path to save log file
//                .fileNameGenerator(new DateFileNameGenerator())        // Default: ChangelessFileNameGenerator("log")
//                // .backupStrategy(new MyBackupStrategy())             // Default: FileSizeBackupStrategy(1024 * 1024)
//                // .cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME))     // Default: NeverCleanStrategy()
//                .flattener(new ClassicFlattener())                     // Default: DefaultFlattener
//                .build();
        XLog.init( // Initialize XLog
            config,  // Specify the log configuration, if not specified, will use new LogConfiguration.Builder().build()
            androidPrinter,
            conslePrinter
        ) //,                                        // Specify printers, if no printer is specified, AndroidPrinter(for Android)/ConsolePrinter(for java) will be used.

        //filePrinter);

        // For future usage: partial usage in MainActivity.
//        globalFilePrinter = filePrinter;
//
//        // Intercept all logs(including logs logged by third party modules/libraries) and print them to file.
//        LibCat.config(true, filePrinter);
    }

    companion object {
        val instance: App? = null
    }
}